package nc.ui.eh.ehld.z105501;

import java.awt.Container;
import java.util.ArrayList;

import nc.ui.eh.ehld.z103001.b;
import nc.ui.eh.ehld.z103001.c;
import nc.ui.pub.bill.BillItem;
import nc.ui.scm.pub.sourceref.BillRefListPanel;
import nc.ui.scm.pub.sourceref.BillToBillRefPanel;
import nc.ui.scm.pub.sourceref.IBillReferQueryProxy;
import nc.ui.scm.pub.sourceref.SimpBillRefListPanel;
import nc.ui.scm.pub.sourceref.SourceRefDlg;
import nc.ui.scm.pub.sourceref.BillToBillRefPanel.ShowState;
import nc.ui.scm.util.ObjectUtils;
import nc.vo.pub.bill.BillTempletBodyVO;
import nc.vo.pub.bill.BillTempletVO;

public class GetLDPreOrder extends SourceRefDlg{

	public GetLDPreOrder(String pkField, String pkCorp, String operator, String funNode, String queryWhere, String billType, String businessType, String templateId, String currentBillType, Container parent) {
		super(pkField, pkCorp, operator, funNode, queryWhere, billType, businessType,
				templateId, currentBillType, parent);
		// TODO Auto-generated constructor stub
	}
	@Override
	protected BillToBillRefPanel createBillToBillRefPanel() {
		// TODO Auto-generated method stub
		try{
		      billtobillrefpanel = new BillToBillRefPanel();
		      BillRefListPanel billref = createDoubleTableListPanel(); 
		      SimpBillRefListPanel simpbillref = createOneTableListPanel();
		     
		      BillTempletVO tvo = billref.getDefaultTemplet(getBillType(), getBusinessType(),
		          getOperator(), getPkCorp(),billref.getRefNodeCode());
		      tvo = (BillTempletVO)ObjectUtils.serializableClone(tvo);
		      BillTempletBodyVO[] bvos = tvo.getBodyVO();
		      ArrayList<BillTempletBodyVO> listvos = new ArrayList<BillTempletBodyVO>();
		      for(BillTempletBodyVO bvo : bvos){
//		        if(bvo.getPos()!=null && bvo.getPos().intValue() == BillItem.BODY 
//		            && bvo.getTable_code()!=null && !bvo.getTable_code().equals("ehzg_sale_contract_b"))
//		          continue;
		        listvos.add(bvo);
		      }
		      tvo.setChildrenVO(listvos.toArray(new BillTempletBodyVO[listvos.size()]));
		      billref.createBillListPanel(tvo);
		      simpbillref.createBillListPanel(tvo);
		      billtobillrefpanel.createUI(billref, simpbillref);
		      if(getQueyDlg()!=null && (getQueyDlg() instanceof IBillReferQueryProxy)){
		        if(((IBillReferQueryProxy)getQueyDlg()).isShowDoubleTableRef()){
		          billtobillrefpanel.switchShow(ShowState.DoubleTable);
		        }else{
		          billtobillrefpanel.switchShow(ShowState.OneTable);
		        }
		      }
//		      IBillToBillListPanel billListPanel=billtobillrefpanel.getCurBillListPanel();
//		      BillRefListPanel listPanel=(BillRefListPanel)billListPanel;
		      
		      return billtobillrefpanel;
		    }catch(Exception e){
		      handleException(e);
		      return null;
		    }
	}
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Override
	protected BillRefListPanel createDoubleTableListPanel() {
		// TODO Auto-generated method stub
		return new b(getBusinessType(), getBillType(), getCurrentBillType(),
				getPkCorp());
	}

	@Override
	protected SimpBillRefListPanel createOneTableListPanel() {
		// TODO Auto-generated method stub
		return new c(getBusinessType(), getBillType(), getCurrentBillType(),
				getPkCorp());
	}
}
